package cn.wolfcode.job;

import cn.wolfcode.cache.IStrategyCommentRedisService;
import cn.wolfcode.cache.vo.StrategyStatisVO;
import cn.wolfcode.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
//@Component
public class RedisDataPersistenceJob {
    @Autowired
    private IStrategyCommentRedisService strategyCommentRedisService;
    @Autowired
    private IStrategyService strategyService;

    @Scheduled(cron = "0/10 * * * * ?")
    public void doWork(){
        //1:查询redis中所有的vo对象集合
        List<StrategyStatisVO> vos =  strategyCommentRedisService.queryStrategyVoByPattern("*");
        //2:遍历vo对象 update 到mongodb中去
        for (StrategyStatisVO vo : vos) {
            strategyService.updateStrategyVo(vo);
        }
    }
}
